using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Castle.ActiveRecord;
using NHibernate.Expression;

/// <summary>
/// Summary description for Gallery
/// </summary>
/// 


[ActiveRecord("Gallery")]
public class Gallery : ActiveRecordBase<Gallery>
{

    public static MatchMode Exact = NHibernate.Expression.MatchMode.Exact;
    public static MatchMode Anywhere = NHibernate.Expression.MatchMode.Anywhere;
    public static MatchMode End = NHibernate.Expression.MatchMode.End;
    public static MatchMode Start = NHibernate.Expression.MatchMode.Start;


    private int galleryID;

    [PrimaryKey(PrimaryKeyType.Identity)]
    public int GalleryID
    {
      get { return galleryID; }
      set { galleryID = value; }
    }

    private String caption;

    [Property]
    public String Caption
    {
      get { return caption; }
      set { caption = value; }
    }
    private String description;

    [Property]
    public String Description
    {
      get { return description; }
      set { description = value; }
    }

    private bool activeFlag;

    [Property]
    public bool ActiveFlag
    {
        get { return activeFlag; }
        set { activeFlag = value; }
    }

    private DateTime createdDate;

    [Property]
    public DateTime CreatedDate
    {
        get { return createdDate; }
        set { createdDate = value; }
    }

    private DateTime updatedDate;
    [Property]
    public DateTime UpdatedDate
    {
        get { return updatedDate; }
        set { updatedDate = value; }
    }

    private String createdBy;
    [Property]
    public String CreatedBy
    {
        get { return createdBy; }
        set { createdBy = value; }
    }


    private String updatedBy;

    [Property]
    public String UpdatedBy
    {
        get { return updatedBy; }
        set { updatedBy = value; }
    }

	public Gallery()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public Gallery(String caption,String description,bool active,String createdBy)
    {
        this.caption = caption;
        this.description = description;
        this.activeFlag = active;
        this.createdBy = createdBy;
        this.updatedBy = createdBy;
        this.createdDate = DateTime.Now;
        this.updatedDate = DateTime.Now;
    }

    public static void add_gallery(String caption,String description, bool active, String createdBy)
    {
        Gallery gallery = new Gallery(caption,description,active,createdBy);
        gallery.Create();
    }

    public static void edit_gallery(int galleryID, String caption,String description, String updatedBy)
    {
        Gallery gallery = get_gallery(galleryID);
        gallery.caption = caption;
        gallery.description = description;
        gallery.updatedBy = updatedBy;
        gallery.updatedDate = DateTime.Now;
        gallery.Update();        
    }

    public static void edit_gallery(int galleryID,bool active,String updatedBy)
    {
        Gallery gallery = get_gallery(galleryID);
        gallery.activeFlag = active;
        gallery.updatedBy = updatedBy;
    }

    public static void delete_gallery(int galleryID)
    {
        Gallery gallery = get_gallery(galleryID);
        gallery.Delete();
    }

    public static Gallery get_gallery(int galleryID)
    {
        return FindByPrimaryKey(galleryID);
    }

    public static Gallery[] get_all_gallery()
    {
        return FindAll();
    }

    public static int count_all_gallery()
    {
        return Count();
    }

    public static Gallery[] search_gallery(String propertyName, String textSearch, NHibernate.Expression.MatchMode mode)
    {
        NHibernate.Expression.DetachedCriteria criteria = NHibernate.Expression.DetachedCriteria.For<Gallery>();

        criteria.Add(NHibernate.Expression.Expression.InsensitiveLike(propertyName, textSearch, mode));

        return FindAll(criteria, Gallery.Asc(propertyName));
    }

    public static Gallery[] get_gallery_and_sort(String propertyName, String order)
    {
        NHibernate.Expression.DetachedCriteria avgWeight = NHibernate.Expression.DetachedCriteria.For<Gallery>();
        if (order == "ASC")
            return FindAll(avgWeight, Asc(propertyName));
        return FindAll(avgWeight, Desc(propertyName));
    }
}
